package com.coocaa.ops.api.v1.params.service;

import com.coocaa.ops.api.common.model.HeaderModel;
import com.coocaa.ops.api.common.util.RequestUtil;
import com.coocaa.ops.api.v1.params.model.OpsParamModel;
import com.coocaa.ops.api.v1.params.provider.IParamsProvider;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author zen
 * @date 2020-11-02 16:51
 * @description
 */
@Service
public class ParamsServiceImpl implements ParamsService {

    @Autowired
    private IParamsProvider paramsProvider;

    @Override
    public List<OpsParamModel> getOpsParam(HttpServletRequest request, String type) {
        HeaderModel header = RequestUtil.getHeader(request);
        List<OpsParamModel> opsParamModelList;
        if (StringUtils.isEmpty(type)) {
            opsParamModelList = paramsProvider.getOpsParamModelList(header);
        } else {
            opsParamModelList = paramsProvider.getOpsParamModelList(header, type);
        }
        return opsParamModelList;
    }
}
